/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.googlecode.midpdeviceprofiler;

import com.googlecode.midpdeviceprofiler.ClassProber;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;

/**
 * Form for probing available JSR's.
 *
 * @author Helio Rodrigues.
 */
public class SupportedApisView extends Form {

    private Command backCommand = new Command("Back", Command.BACK, 0);

    /**
     * @return the backCommand
     */
    public Command getBackCommand() {
        return backCommand;
    }

    /**
     * Default constructor.
     */
    public SupportedApisView() {
        super("Supported API's");
        probeAll();
        addCommand(backCommand);
        setCommandListener(DeviceProfilerMidlet.getInstance());
    }

    /**
     * Probes PDA Optional Packages for the J2ME Platform.
     */
    private void probeJsr75PimAndFile() {
        probeClassAndPrintResult("JSR 75, PIM and File:", "javax.microedition.pim.PIMException");
    }

    /**
     * Probes Java APIs for Bluetooth.
     */
    private void probeJsr82BluetoothAndObex() {
        probeClassAndPrintResult("JSR 82, Bluetooth:", "javax.bluetooth.BluetoothStateException");
    }

    /**
     * Probes Mobile Media API.
     */
    private void probeJsr135Mmapi() {
        probeClassAndPrintResult("JSR 135, MMAPI:", "javax.microedition.media.MediaException");
    }

    /**
     * Probes J2ME Web Services Specification.
     */
    private void probeJsr172WebServices() {
        probeClassAndPrintResult("JSR 172, Web Services:", "javax.xml.rpc.JAXRPCException");
    }

    /**
     * Probes Security and Trust Services API for Java ME.
     */
    private void probeJsr177Satsa() {
        probeClassAndPrintResult("JSR 177, SATSA:", "java.security.GeneralSecurityException");
    }

    /**
     * Probes Location API for Java ME.
     */
    private void probeJsr179Location() {
        probeClassAndPrintResult("JSR 179, Location:", "javax.microedition.location.LandmarkException");
    }

    /**
     * Probes Mobile 3D Graphics API for J2ME.
     */
    private void probeJsr1843DGraphics() {
        probeClassAndPrintResult("JSR 184, 3D Graphics:", "javax.microedition.m3g.Group");
    }

    /**
     * Probes Wireless Messaging API.
     */
    private void probeJsr205Wma() {
        probeClassAndPrintResult("JSR 205, WMA:", "javax.wireless.messaging.SizeExceededException");
    }

    /**
     * Probes Content Handler API.
     */
    private void probeJsr211Chapi() {
        probeClassAndPrintResult("JSR 211, CHAPI:", "javax.microedition.content.ContentHandlerException");
    }

    /**
     * Probes Scalable 2D Vector Graphics API for J2ME.
     */
    private void probeJsr226Svg() {
        probeClassAndPrintResult("JSR 226, SVG:", "org.w3c.dom.svg.SVGException");
    }

    /**
     * Probes Advanced Multimedia Supplements.
     */
    private void probeJsr234Amms() {
        probeClassAndPrintResult("JSR 234, AMMS:", "javax.microedition.amms.Spectator");
    }

    /**
     * Probes Java Binding for OpenGL ES API.
     */
    private void probeJsr239OpenGl() {
        probeClassAndPrintResult("JSR 239, OpenGL:", "javax.microedition.khronos.egl.EGLConfig");
    }

    /**
     * Probes Mobile Sensor API.
     */
    private void probeJsr256Sensor() {
        probeClassAndPrintResult("JSR 256, Sensor:", "javax.microedition.sensor.Unit");
    }

    /**
     * Probes Contactless Communication API.
     */
    private void probeJsr257Contactless() {
        probeClassAndPrintResult("JSR 257, Contactless:", "javax.microedition.contactless.ContactlessException");
    }

    /**
     * Probes XML API for Java ME.
     */
    private void probeJsr280Xml() {
        probeClassAndPrintResult("JSR 280, XML:", "javax.xml.parsers.ParserConfigurationException");
    }

    /**
     * Tries to instantiate the test class to verify the existance of the JSR.
     *
     * @param description The JSR name.
     * @param testClass The class used to test the existance of the JSR.
     */
    private void probeClassAndPrintResult(String description, String testClass) {
        StringItem item = new StringItem(description,
                ClassProber.probe(testClass) ? "Yes" : "No");

        append(item);
    }

    /**
     *
     */
    private void probeAll() {
        probeJsr75PimAndFile();
        probeJsr82BluetoothAndObex();
        probeJsr135Mmapi();
        probeJsr172WebServices();
        probeJsr177Satsa();
        probeJsr179Location();
        probeJsr1843DGraphics();
        probeJsr205Wma();
        probeJsr211Chapi();
        probeJsr226Svg();
        probeJsr234Amms();
        probeJsr239OpenGl();
        probeJsr256Sensor();
        probeJsr257Contactless();
        probeJsr280Xml();
    }
}
